$(document).ready(function(){
	disableClick();
	$('#confirm-delete').on('change',function(){
		if(this.checked == true)
		{
			$( 'a#delete-student' ).removeClass('disabled');
			$( 'a#delete-student' ).click(function(e){
				e.preventDefault();
				var theHREF = $(this).attr("href");
				var title = $(this).attr("title");
				var target = $(this).attr('target');

				if(!title ){
					$( '#msgDialog > p' ).html( 'Are You Sure?' );
				}else{
					$( '#msgDialog > p' ).html( title );
				}
				
				$( '#msgDialog' ).dialog( 'option', 'title', 'Confirm' );
				$("#msgDialog").dialog('option', 'buttons', {
						"Confirm" : function() {
								
								if(typeof  target == "undefined")
								{
									window.location.href = theHREF;
								}else{
									$(this).dialog("close");
									window.open(theHREF);
								}
							},
						"Cancel" : function() {
								$(this).dialog("close");
							}
						});
				
				$("#msgDialog").dialog("open");
				$('.ui-dialog-buttonpane').find('button').addClass('btn btn-mini btn-primary');

			});
		}else{
			disableClick();
		}
	});
	
	function disableClick()
	{
		$('a#delete-student').unbind('click').bind('click',function(e){
			e.preventDefault();
		});
		$( 'a#delete-student' ).addClass('disabled');
	}
});

